home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Freeware / sysmon / src / Halt.c < prev    next >
C/C++ Source or Header  |  2002-10-27  |  2KB  |  97 lines

  1. /*
  2. **    $RCSfile: Halt.c,v $
  3. **    $Filename: Halt.c $
  4. **    $Revision: 0.1 $
  5. **    $Date: 1995/04/15 17:33:51 $
  6. **
  7. **    sysmon.library support command Halt (version 0.3)
  8. **    
  9. **    (C) Copyright 1995 by Etienne Vogt
  10. */
  11.  
  12. #include <exec/alerts.h>
  13. #include <dos/dos.h>
  14. #include <workbench/startup.h>
  15. #define __USE_SYSBASE
  16. #include <proto/exec.h>
  17. #include <proto/dos.h>
  18. #include "sysmon.h"
  19. #include "sysmon_protos.h"
  20. #include "sysmon_pragmas.h"
  21. #include <string.h>
  22.  
  23. struct ExecBase *SysBase;
  24. struct DosLibrary *DOSBase;
  25. struct Library *SysmonBase;
  26. static struct WBStartup *wbmsg;
  27. static struct RDArgs *myrda;
  28.  
  29. static UBYTE version[] = "$VER: Halt 0.3 (5.8.95)";
  30. static UBYTE template[] = "REBOOT/S,REKICK/S";
  31.  
  32. #define    OPT_REBOOT    0
  33. #define    OPT_REKICK    1
  34. #define OPTMAX        2
  35.  
  36. ULONG __saveds main(void);
  37. static void cleanexit(ULONG rc);
  38. static void KPrintf(STRPTR fmt, ...);
  39.  
  40. ULONG __saveds main(void)    /* No startup code */
  41. {
  42.   struct Process *myproc;
  43.   LONG opts[OPTMAX];
  44.   ULONG flags = NULL;
  45.  
  46.   SysBase = *(struct ExecBase **)4;
  47.   DOSBase = NULL;
  48.   SysmonBase = NULL;
  49.   wbmsg = NULL;
  50.   myrda = NULL;
  51.  
  52.   myproc = (struct Process *)FindTask(NULL);
  53.   if ((DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",36)) == NULL)
  54.   { Alert(AT_Recovery|AG_OpenLib|AO_DOSLib);
  55.     return 100;
  56.   }
  57.  
  58.   if (!(myproc->pr_CLI))        /* If started from WB, exit cleanly */
  59.   { WaitPort(&(myproc->pr_MsgPort));
  60.     wbmsg = (struct WBStartup *)GetMsg(&(myproc->pr_MsgPort));
  61.     cleanexit(20);
  62.   }
  63.   else
  64.   { if ((SysmonBase = OpenLibrary("sysmon.library",0)) == NULL)
  65.     { Printf("Halt failed : Couldn't open sysmon.library\n");
  66.       cleanexit(20);
  67.     }
  68.     memset((char *)opts, 0, sizeof(opts));
  69.     if ((myrda = ReadArgs(template, opts, NULL)) == NULL)
  70.     { PrintFault(IoErr(),"Halt failed");
  71.       cleanexit(20);
  72.     }
  73.     if (opts[OPT_REBOOT]) flags |= HALTF_REBOOT;
  74.     if (opts[OPT_REKICK]) flags |= HALTF_REKICK;
  75.     KPrintf("\a\a\aSystem going down...");
  76.     smHalt(flags);            /* Never returns...    */
  77.   }
  78.  
  79.   cleanexit(0);
  80. }
  81.  
  82. static void cleanexit(ULONG rc)
  83. {
  84.   if (myrda) FreeArgs(myrda);
  85.   if (DOSBase) CloseLibrary((struct Library *)DOSBase);
  86.   if (SysmonBase) CloseLibrary(SysmonBase);
  87.   if (wbmsg)
  88.   { Forbid();
  89.     ReplyMsg((struct Message *)wbmsg);
  90.   }
  91.   Exit(rc);
  92. }
  93.  
  94. static void KPrintf(STRPTR fmt, ...)
  95. { smVKPrintf(fmt, &fmt + 1);
  96. }
  97.